package com.ithaima.controller;

import com.ithaima.service.UserService;
import com.ithaima.vo.req.LoginReqVo;
import com.ithaima.vo.resp.LoginRespVo;
import com.ithaima.vo.resp.R;
import com.itheima.stock.pojo.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author by itheima
 * @Date 2022/6/29
 * @Description 定义用户处理器接口
 */
@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    @GetMapping("/user/{userName}")
    public SysUser getUserByUserName(@PathVariable("userName") String userName) {
        return userService.findBayName(userName);
    }

    /**
     * 用户登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public R<LoginRespVo> loginUser(@RequestBody LoginReqVo user){
      return  userService.loginUser(user);
    }
}
